import { GetEcharts } from '@/utils/echarts'
import * as echarts from 'echarts';
import { autoHover } from "@/utils/publicmethods/tooltip";
import { getfadianlistapi, getmongthuserapi } from '@/api/ElectricalDistribution/SX-hrss'
import {timeArray} from '@/utils/array'
// 实时负荷
export const getresltimeechart = async(that, dom,entity) => {
  let option = {
    tooltip: {
      trigger: "axis",
      backgroundColor: "rgba(50,50,50,0.3)",
      borderColor: "#fff",
      textStyle: {
        color: "#fff",
      },
    },
    legend: {
      data: ["kW"],
    },
    grid: {
      top:'6%',
      left: "1%",
      right: "3%",
      bottom: "5%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: timeArray,
    },
    yAxis: {
      splitLine: {
        // 网格线
        lineStyle: {
          type: "dashed", // 设置网格线类型 dotted：虚线   solid:实线
          color: "#333",
        },
        show: true, // 隐藏或显示
      },
      type: "value",
      name: "(kW)",
    },
    series: [
      {
        name: "实时负荷",
        type: "line",
        // symbol: 'none',
        symbolSize: "0",
        smooth: true,
        data:JSON.parse(entity.loadCurDayPointsArray) ,
        lineStyle: {
          color: "#1697da",
        },
        areaStyle: {
          normal: {
            // 前四个参数代表位置 左下右上，如下表示从上往下渐变色 暗青色到亮青色，
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "rgba(12,180,250, 1)" },
              { offset: 1, color: "rgba(63, 208, 249, 0)" },
            ]),
          },
        },
      },
    ],
  }
  GetEcharts(that, dom, option)
  autoHover(echarts.init(dom), option, 12, 3000,false)
}
// 月能耗
export const getmonthenergyechart = async(that, dom) => {
  const { data: { list } } = await getmongthuserapi({ subburo: '88000341' })
  let option = {
    xAxis: {
      type: 'category',
      data: list.map(ele=>ele.timeReading)
    },
    tooltip: {
      trigger: "axis",
      backgroundColor: "rgba(50,50,50,0.3)",
      borderColor: "#fff",
      textStyle: {
        color: "#fff",
      },
    },
    color: '#5087ec',
    grid: {
      top:'6%',
      left: "5%",
      right: "3%",
      bottom: "5%",
      containLabel: true,
    },
    yAxis: {
      splitLine: {
        // 网格线
        lineStyle: {
          type: 'dashed', // 设置网格线类型 dotted：虚线   solid:实线
          color: '#333'
        },
        show: true // 隐藏或显示
      },
      type: 'value'
    },
    series: [
      {
        data: list.map(ele=>ele.valueReading),
        type: 'line',
        symbolSize: 6, 
        areaStyle: {
          normal: {
            //前四个参数代表位置 左下右上，如下表示从上往下渐变色 暗青色到亮青色，
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#5087ec' },
              { offset: 1, color: 'rgba(12, 17, 39, 0.5)' }
            ])
          }
        }
      }
    ]
  }
  GetEcharts(that, dom, option)
  autoHover(echarts.init(dom), option, 7, 3000,false)
}
// 日发电
export const getrifadianechart =async (that, dom) => {
  const {data:{list}} = await getfadianlistapi({ subburo: '88000341' })
  const timePoints = list.find(ele => ele.datalist.length)?.datalist.map(item => item.timeReading)
  let option = {
    color: ['#5087ec', '#68bbc4'],
    tooltip: {
      trigger: 'axis',
      backgroundColor: 'rgba(50,50,50,0.3)',
      borderColor: '#fff',
      textStyle: {
        color: '#fff'
      }
    },
    grid: {
      top: '12%',
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    legend: {
      top:'0%',
      textStyle: {
        color:'#fff'
      }
    },
    xAxis: [
      {
        type: 'category',
        data: timePoints
      }
    ],
    yAxis: [
      {
        splitLine: {
          // 网格线
          lineStyle: {
            type: 'dashed', // 设置网格线类型 dotted：虚线   solid:实线
            color: '#333'
          },
          show: true // 隐藏或显示
        },
        type: 'value'
      },
      {
        splitLine: {
          // 网格线
          lineStyle: {
            type: 'dashed', // 设置网格线类型 dotted：虚线   solid:实线
            color: '#333'
          },
          show: true // 隐藏或显示
        },
        type: 'value'
      }
    ],
    series: [
      {
        type: 'bar',
        name: '日发电量',
        data: list.find(ele=>ele.name=='发电量').datalist.map(ele=>ele.valueReading) 
      },
      {
        type: 'line',
        symbolSize: 6, 
        name: '日消纳率',
        data: list.find(ele=>ele.name=='消纳率').datalist.map(ele=>ele.valueReading) ,
        yAxisIndex: 1
      }
    ]
  }
  GetEcharts(that, dom, option)
  autoHover(echarts.init(dom), option, 4, 3000,false)
}